package com.gitee.wsl.common.ui.theme.tokens

import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import com.gitee.wsl.common.ui.ext.end
import com.gitee.wsl.common.ui.ext.top

enum class ShapeKeyTokens {
    CornerExtraLarge,
    CornerExtraLargeTop,
    CornerExtraSmall,
    CornerExtraSmallTop,
    CornerFull,
    CornerLarge,
    CornerLargeEnd,
    CornerLargeTop,
    CornerMedium,
    CornerNone,
    CornerSmall;
    companion object{
        val cornerExtraLarge = CornerExtraLarge
        val cornerExtraLargeTop = CornerExtraLargeTop
        val cornerExtraSmall = CornerExtraSmall
        val cornerExtraSmallTop = CornerExtraSmallTop
        val cornerFull = CornerFull
        val cornerLarge = CornerLarge
        val cornerLargeEnd = CornerLargeEnd
        val cornerLargeTop = CornerLargeTop
        val cornerMedium = CornerMedium
        val cornerNone = CornerNone
        val cornerSmall = CornerSmall
    }
}


/**
 * Helper function for component shape tokens. Here is an example on how to use component color
 * tokens:
 * ``MaterialTheme.shapes.fromToken(FabPrimarySmallTokens.ContainerShape)``
 */
fun Shapes.fromToken(value: ShapeKeyTokens): Shape {
    return when (value) {
        ShapeKeyTokens.CornerExtraLarge -> extraLarge
        ShapeKeyTokens.CornerExtraLargeTop -> extraLarge.top()
        ShapeKeyTokens.CornerExtraSmall -> extraSmall
        ShapeKeyTokens.CornerExtraSmallTop -> extraSmall.top()
        ShapeKeyTokens.CornerFull -> CircleShape
        ShapeKeyTokens.CornerLarge -> large
        ShapeKeyTokens.CornerLargeEnd -> large.end()
        ShapeKeyTokens.CornerLargeTop -> large.top()
        ShapeKeyTokens.CornerMedium -> medium
        ShapeKeyTokens.CornerNone -> RectangleShape
        ShapeKeyTokens.CornerSmall -> small
    }
}

val Shapes.extraSmallTop get() = extraSmall.top()
val Shapes.extraLargeTop get() = extraLarge.top()
val Shapes.largeEnd get() = large.end()
val Shapes.largeTop get() = large.top()

/** Converts a shape token key to the local shape provided by the theme */
@ReadOnlyComposable
@Composable
fun ShapeKeyTokens.toShape(): Shape {
    return MaterialTheme.shapes.fromToken(this)
}

/** CompositionLocal used to specify the default shapes for the surfaces. */
//val LocalShapes = staticCompositionLocalOf { Shapes() }

val MaterialTheme.shapesToken get() = ShapeKeyTokens